import type { ApiResponse } from "@/api/type.ts"
import request from "@/api/config/request.ts"

export interface MenuStructure {
  id: number
  name: string
  url: string
  icon: string
  pid: number
  children?: MenuStructure[]
}

export interface MenuResponse {
  menus: MenuStructure[]
}

export const getMenuListApi = (): Promise<ApiResponse<MenuResponse>> => {
  return request.get("/menu/getList")
}

export const addMenuApi = (
  data: MenuStructure
): Promise<ApiResponse<MenuStructure>> => {
  return request.post("/menu/create", data)
}

export const updateMenuApi = (
  data: MenuStructure
): Promise<ApiResponse<MenuStructure>> => {
  return request.put("/menu/update", data)
}

export const deleteMenuApi = (id: number): Promise<ApiResponse> => {
  return request.post("/menu/delete", { id })
}
